﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using RegisterationCommon.Common;
using System.Data;
using RegisterationCommon.Student;
using RegisterationCommon.Education;
using System.IO;
namespace RegisterationSystem.Space_Education
{
    public partial class ServicesDivision : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.Form["action"] != "")
                {
                    switch (Request.Form["action"])
                    {
                        case "pswdreset":
                            UpdStudentPswdReset();
                            break;
                        case "updateallservicesdivisionInfo":
                            UpdateAllServicesDivisionInfo();
                            break;
                        //case "derive_excelList":
                        //    derive_excelList();
                        //    break;
                        //case "derive_excelListAll":
                        //    derive_excelListAll();
                        //    break;
                    }
                }
            }
        }
        //根据id重置学生帐号密码
        void UpdStudentPswdReset()
        {
            string id = Request.Form["id"].ToString();
            string StudentPswd = Request.Form["StudentPswd"].ToString();
            StudentInfo s = new StudentInfo();
            s.MdfAccountPwd(Convert.ToInt64(id), BaseLibrary.ConvertToMD5(StudentPswd.ToLower()));
        }
        #region 教育局进行服务划分
        /// <summary>
        /// 教育局进行服务划分
        /// </summary>
        /// <param name="context"></param>
        void UpdateAllServicesDivisionInfo()
        {
            string flag = "-1n";
            int scommunityID = Convert.ToInt32(Request.Form["scommunityID"].ToString());
            int xcommunityID = Convert.ToInt32(Request.Form["xcommunityID"].ToString());
            int pcommunityID = Convert.ToInt32(Request.Form["pcommunityID"].ToString());
            int schoolID = Convert.ToInt32(Request.Form["schoolID"].ToString());
            string txtHouseNumber1 = Request.Form["txtHouseNumber1"].ToString();//得到门栋
            string txtHouseNumber2 = Request.Form["txtHouseNumber2"].ToString();//得到门栋
            //string txtHouseNumber1 = "";//得到门栋
            StudentInfo s = new StudentInfo();

            //if (txtHouseNumber1 == "" || txtHouseNumber1 == null)
            //{
                if (scommunityID == -1)//社区为全部（一个片区）
                {
                    RParams param = new RParams();
                    param.Add("SchID", schoolID);
                    param.Add("ServicesDivision", 1);
                    param.Add("Ext2", 1);//1为服务划分
                    param.Add("Status", 1);//已分配
                    //DBAction.Update(ETableName.Students, "SchID,ServicesDivision,Ext2", "ScommAreaID=" + scommunityID + " and IsSelf=1 and (Ext3='' or Ext3='1') ", param);
                    DBAction.Update(ETableName.Students, "SchID,ServicesDivision,Ext2,Status", "pianid=" + pcommunityID + " and IsSelf=0 and (Ext3='' or Ext3='1') and Ext5='' and IsMatured=1 ", param);
                    flag = "ok";
                }
                else if (xcommunityID == -1)//小区为全部（片区+社区）
                {
                    RParams param = new RParams();
                    param.Add("SchID", schoolID);
                    param.Add("ServicesDivision", 1);
                    param.Add("Ext2", 1);//1为服务划分
                    param.Add("Status", 1);//已分配
                    //DBAction.Update(ETableName.Students, "SchID,ServicesDivision,Ext2", "ScommAreaID=" + scommunityID + " and IsSelf=1 and (Ext3='' or Ext3='1') ", param);
                    DBAction.Update(ETableName.Students, "SchID,ServicesDivision,Ext2,Status", "pianid=" + pcommunityID + " and ScommAreaID=" + scommunityID + " and IsSelf=0 and (Ext3='' or Ext3='1') and Ext5='' and IsMatured=1 ", param);
                    flag = "ok";
                }
                else//小区也选择（片区+社区+小区）
                {
                    if (xcommunityID == 481)//小区为滨湖25-47、67-71栋
                    {
                        RParams param = new RParams();
                        param.Add("SchID", schoolID);
                        param.Add("ServicesDivision", 1);
                        param.Add("Ext2", 1);//1为服务划分
                        param.Add("Status", 1);//已分配
                        //DBAction.Update(ETableName.Students, "SchID,ServicesDivision,Ext2", "ScommAreaID=" + scommunityID + " and IsSelf=1 and (Ext3='' or Ext3='1') ", param);
                        DBAction.Update(ETableName.Students, "SchID,ServicesDivision,Ext2,Status", "pianid=" + pcommunityID + " and ScommAreaID=" + scommunityID + " and IsSelf=0 and (Ext3='' or Ext3='1') and Ext5='' and IsMatured=1 " + " and ((Ext1 between '25' and '47') or (Ext1 between '67' and '71'))", param);
                        flag = "ok";
                    }
                    else if (xcommunityID == 482)//小区为滨湖其他
                    {
                        RParams param = new RParams();
                        param.Add("SchID", schoolID);
                        param.Add("ServicesDivision", 1);
                        param.Add("Ext2", 1);//1为服务划分
                        param.Add("Status", 1);//已分配
                        //DBAction.Update(ETableName.Students, "SchID,ServicesDivision,Ext2", "ScommAreaID=" + scommunityID + " and IsSelf=1 and (Ext3='' or Ext3='1') ", param);
                        DBAction.Update(ETableName.Students, "SchID,ServicesDivision,Ext2,Status", "pianid=" + pcommunityID + " and ScommAreaID=" + scommunityID + " and IsSelf=0 and (Ext3='' or Ext3='1') and Ext5='' and IsMatured=1 " + " and (Ext1< '25' and Ext1>'47' Ext1<'67' and Ext1>'71')", param);
                        flag = "ok";
                    }
                    else//不是滨湖小区
                    {
                        RParams param = new RParams();
                        param.Add("SchID", schoolID);
                        param.Add("ServicesDivision", 1);
                        param.Add("Ext2", 1);//1为服务划分
                        param.Add("Status", 1);//已分配
                        //DBAction.Update(ETableName.Students, "SchID,ServicesDivision,Ext2", "ScommAreaID=" + scommunityID + " and IsSelf=1 and (Ext3='' or Ext3='1') ", param);
                        DBAction.Update(ETableName.Students, "SchID,ServicesDivision,Ext2,Status", "pianid=" + pcommunityID + " and XcommAreaID=" + xcommunityID + " and ScommAreaID=" + scommunityID + " and IsSelf=0 and (Ext3='' or Ext3='1') and Ext5='' and IsMatured=1 ", param);
                        flag = "ok";
                    }

                }



            //    if (scommunityID == 104)
            //    {
            //        RParams param = new RParams();
            //        param.Add("SchID", schoolID);
            //        param.Add("ServicesDivision", 1);
            //        param.Add("Ext2", 1);//1为服务划分
            //        //DBAction.Update(ETableName.Students, "SchID,ServicesDivision,Ext2", "ScommAreaID=" + scommunityID + " and IsSelf=1 and (Ext3='' or Ext3='1') ", param);
            //        DBAction.Update(ETableName.Students, "SchID,ServicesDivision,Ext2", "IsSelf=1 and (Ext3='' or Ext3='1') and Ext5='' and IsMatured=1 ", param);
            //        flag = "ok";
            //    }
            //    else if (xcommunityID == -1)//所有社区，但不包括其他这个社区
            //    {
            //        //所有社区编号为scommunityID划分
            //        //s.UpdateStudentInfo(scommunityID, schoolID);
            //        RParams param = new RParams();
            //        param.Add("SchID", schoolID);
            //        param.Add("ServicesDivision", 1);
            //        param.Add("Ext2", 1);//1为服务划分
            //        DBAction.Update(ETableName.Students, "SchID,ServicesDivision,Ext2", "ScommAreaID=" + scommunityID + " and IsSelf=0 and (Ext3='' or Ext3='1') and Ext5='' and IsMatured=1 ", param);
            //        flag = "ok";
            //    }
            //    else
            //    {
            //        RParams param = new RParams();
            //        param.Add("SchID", schoolID);
            //        param.Add("ServicesDivision", 1);
            //        param.Add("Ext2", 1);//1为服务划分
            //        DBAction.Update(ETableName.Students, "SchID,ServicesDivision,Ext2", "ScommAreaID=" + scommunityID + " and XcommAreaID=" + xcommunityID + " and IsSelf=0 and (Ext3='' or Ext3='1')  and Ext5='' and IsMatured=1 ", param);
            //        flag = "ok";
            //    }

            //}
            //else
            //{
            //    if (scommunityID == 104)
            //    {
            //        RParams param = new RParams();
            //        param.Add("SchID", schoolID);
            //        param.Add("ServicesDivision", 1);
            //        param.Add("Ext2", 1);//1为服务划分
            //        DBAction.Update(ETableName.Students, "SchID,ServicesDivision,Ext2", "ScommAreaID=" + scommunityID + " and IsSelf=1 and (Ext3='' or Ext3='1') and Ext5='' and IsMatured=1 " + " and Ext1 between '" + txtHouseNumber1 + "' and '" + txtHouseNumber2 + "'", param);
            //        flag = "ok";
            //    }
            //    else if (xcommunityID == -1)//所有社区，但不包括其他这个社区
            //    {
            //        //所有社区编号为scommunityID划分
            //        //s.UpdateStudentInfo(scommunityID, schoolID);
            //        RParams param = new RParams();
            //        param.Add("SchID", schoolID);
            //        param.Add("ServicesDivision", 1);
            //        param.Add("Ext2", 1);//1为服务划分
            //        DBAction.Update(ETableName.Students, "SchID,ServicesDivision,Ext2", "ScommAreaID=" + scommunityID + " and IsSelf=0 and (Ext3='' or Ext3='1') and Ext5='' and IsMatured=1  " + " and Ext1 between '" + txtHouseNumber1 + "' and '" + txtHouseNumber2 + "'", param);
            //        flag = "ok";
            //    }
            //    else
            //    {
            //        RParams param = new RParams();
            //        param.Add("SchID", schoolID);
            //        param.Add("ServicesDivision", 1);
            //        param.Add("Ext2", 1);//1为服务划分
            //        DBAction.Update(ETableName.Students, "SchID,ServicesDivision,Ext2", "ScommAreaID=" + scommunityID + " and XcommAreaID=" + xcommunityID + " and IsSelf=0 and (Ext3='' or Ext3='1') and Ext5='' and IsMatured=1 " + " and Ext1 between '" + txtHouseNumber2 + "' and '" + txtHouseNumber1 + "'", param);
            //        flag = "ok";
            //    }
            //}



            //if (xcommunityID == -1 && scommunityID!=104)
            //{
            //    //所有社区编号为scommunityID划分
            //    s.UpdateStudentInfo(scommunityID, schoolID);
            //    flag = "ok";
            //}
            //else if (txtHouseNumber1 == ""||txtHouseNumber1==null)//不要求对门栋进行划分
            //{
            //    RParams param = new RParams();
            //    param.Add("SchID", schoolID);
            //    param.Add("ServicesDivision", 1);
            //    DBAction.Update(ETableName.Students, "SchID,ServicesDivision", "ScommAreaID=" + scommunityID + " and XcommAreaID=" + xcommunityID, param);
            //    flag = "ok";
            //}
            //else//当有门栋时
            //{
            //    RParams param = new RParams();
            //    param.Add("SchID", schoolID);
            //    param.Add("ServicesDivision", 1);
            //    DBAction.Update(ETableName.Students, "SchID,ServicesDivision", "ScommAreaID=" + scommunityID + " and XcommAreaID=" + xcommunityID+" and Ext1="+txtHouseNumber1, param);
            //    flag = "ok";
            //}
            Response.Clear();
            Response.Write(flag);
            Response.End();
        }
        #endregion
    }
}